(function($) {

buildpress_admin = {
	
	init: function() {
		
		$(".delete_theme").click(function() {
			var id = $(this).parent().parent().parent().parent().attr("id").split("-");
			id = id[1];
			buildpress_admin.delete_theme(id);
		});
		
		$(".activate_theme").click(function() {
			var id = $(this).parent().parent().parent().parent().attr("id").split("-");
			id = id[1];
			buildpress_admin.activate_theme(id,this);
		
		});
	},
	
	delete_theme: function(tid) {
			$.ajax({
			   type: "POST",
			   url: ajaxurl,
			   data: {action: "BP_delete_theme", _ajax_delete_theme:nonce, id:tid },
			   beforeSend: function() {
					$("#theme-"+tid).animate({'backgroundColor':'#fb6c6c'},300);
			   },
			   success: function(msg){
				   $("#theme-"+tid).fadeOut( function() { $(this).remove() });
			   },
			   failure: function(msg) {
					alert("There seems to be a problem with your connection, try again.");   
			   }
			 });
	},
	
	activate_theme: function(tid,t) {
		var submitProgress = $("#theme-"+tid).find('span.progress');
		submitProgress.show();
			$.ajax({
			   type: "POST",
			   url: ajaxurl,
			   data: {action: "BP_activate_theme", _ajax_activate_theme:nonce, id:tid },
			   success: function(msg){
   				   $(".active .activate_theme").html("Activate"); //make all text Activated to Acitve
				   $(t).html("Activated"); //make the current as Activated
				   $(".active").removeAttr("class"); //remove .active class in prev
				   $("#theme-"+tid).attr("class","active"); //add .active class in current
				   submitProgress.hide();
			   },
			   failure: function(msg) {
					alert("There seems to be a problem with your connection, try again.");   
			   }
			 });	
	}
};

$(document).ready(function(){ buildpress_admin.init(); });

})(jQuery);
